package top.sirgo.jasper.demo;

import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class JasperOrder {

    public static void main(String[] args) throws JRException {
        String basePath = "D:\\workspace\\jasperdemo\\";

        String xmlFile = basePath + "src/main/resources/order.jrxml";
        JasperReport jreport = JasperCompileManager.compileReport(xmlFile);

        ArrayList<OrderListModel> orders = new ArrayList<OrderListModel>();

        for (int i = 0; i < 10; i++) {
            OrderListModel orderListModel = new OrderListModel();
            orderListModel.setCardId(123L);
            orderListModel.setCardNo("456");
            orderListModel.setName("444");
            orderListModel.setCreateTime(new Date());
            orderListModel.setTotalFee(new BigDecimal("100"));
            orderListModel.setPayTypeStr("sas");
            orderListModel.setOrderStatusStr("sss");
            orders.add(orderListModel);
        }

        JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(orders);

        Map params = new HashMap();
       // params.put("datasource", ds);

        JasperPrint jprint = JasperFillManager.fillReport(jreport,  params,ds);

        JasperExportManager.exportReportToPdfFile(jprint, basePath + "src/main/resources/order.pdf");
    }
}